﻿using CraftParameterConfig.Domain.Entity;
using CraftParameterConfig.Domain.Interfaces;
using CraftParameterConfig.Services.Interfaces;
using CraftParameterConfig.Services.Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CraftParameterConfig.Services.Data
{
    public class TableNameService : ITableNameService
    {
        ITableNameRespository respository;
        public TableNameService(ITableNameRespository respository)
        {
            this.respository = respository;
        }
        public string AddTable(TableNameDTO tableName)
        {
            TableNameConfig tableNameConfig = new TableNameConfig(tableName.Name);
            tableNameConfig.CREATE_USER = "SC";

            try
            {
                respository.Add(tableNameConfig);
                MessageBox.Show("新增数据成功!");
                return tableNameConfig.GuidID.ToString();
            }
            catch (Exception)
            {
                throw;
            }
        }

        public void DeleteTable(string guidId)
        {
            try
            {
                respository.Delete(Guid.Parse(guidId));
                MessageBox.Show("删除数据成功!");
            }
            catch (Exception)
            {
                throw;
            }
        }

        public TableNameDTO GetEntity(string guid)
        {
            TableNameDTO entity = new TableNameDTO();
            var source = respository.GetEntityByGuid(Guid.Parse(guid));
            entity.Name = source.Name;
            return entity;
        }

        public DataTable GetTable()
        {
            return respository.GetTable("");
        }
    }
}
